﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WorkOrder.Business;

namespace WorkOrder
{
    public partial class ChaProType : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null || Session["UserID"].ToString() == "")
            {
                Session.Clear();
                ClientScript.RegisterClientScriptBlock(this.GetType(), "windowhref", "<script type='text/javascript'>alert('对不起，您还没有登录系统！');window.parent.location.href='../login.aspx';</script>");
            }
        }

        #region gridView的RowCommand事件
        protected void gvReport_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                if (new Business_Table_Permission().HasDelete(Session["UserID"].ToString(), "Table_Changeover_problems_type"))
                {
                    if (new Business_Table_Changeover_problems_type().Delete("changeover_problems_type_id", e.CommandArgument.ToString()))
                        RefreshData();
                }
                else
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "widowhref", "<script type='text/javascript'>alert('对不起，您没有删除此信息的权限！');</script>");
            }
        }
        #endregion
        private void RefreshData()
        {
            #region 查询数据
            Business_Table_Changeover_problems_type B_T_Deb = new Business_Table_Changeover_problems_type();
            string sqlstr = "1=1";
            if (!string.IsNullOrEmpty(txtName.Text.Trim()))
                sqlstr += " and changeover_problems_type_name like '%" + Server.HtmlEncode(txtName.Text.Trim()) + "%'";
            GridView1.DataSource = B_T_Deb.GetDatas(sqlstr);
            GridView1.DataBind();
            #endregion
        }

        #region 处理光标行颜色事件
        protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex >= 0)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor,this.style.background='#ffe3a0'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
        }
        #endregion

        #region 查询按钮事件
        protected void btnSearch_ServerClick(object sender, EventArgs e)
        {
            RefreshData();
        }
        #endregion
    }
}
